﻿var Table = LayuiHelp.TableLayui();
Table.TablePanel = "panoTable";
Table.Column = [{
	txtName: "项目名称",
	valueCode: "name",
	width: '40%'
},
{
	txtName: "创建时间",
	valueCode: "createTime",
	width: '20%'
},
{
	txtName: "作者",
	valueCode: "createuserid",
	width: '20%'
},
{
	txtName: "操作",
	valueCode: "action",
	width: '20%'
}];
Table.PageIndex = 1;
loadPano();

function loadPano(){
	var send = {
		url:'/vpoi/search',
		success:function(result){
			Table.data = result.rows;
			for(var i=0;i<Table.data.length;i++){
				Table.data[i].action = '<button class="layui-btn layui-btn-small" onclick="searchPano('+i+')">查看</button><button class="layui-btn layui-btn-small layui-btn-normal" onclick="editPano('+i+')">编辑</button><button class="layui-btn layui-btn-small layui-btn-danger" onclick="removePano('+i+')">删除</button>'
			}
			Table.CreateTableFrame();
		}
	};
	sendAjax(send);
}

function addPano() {
	$('#panoForm')[0].reset();
	layui.use('upload', function() {
		layui.upload({
			type:'file',
			ext:'jpg',
			url : '',
			success : function(res) {

			}
		});
	});
	layui.use('form', function() {
		var index = layui.layer.open({
			type : 1,
			content : $('#panoForm')
		});
		layer.style(index, {
			width : '500px',
			height : '400px'
		});
		layer.title('新建项目', index);
		var form = layui.form();
		form.on('submit(submitForm)', function(data){
			var send = {
				url:'/vpoi/create',
				data:$('#panoForm').serialize(),
				success : function(result) {
					layer.msg(result.message, {
						offset : 't',
						anim : 6
					});
					layer.close(index);
					loadPano();
				}
			};
			sendAjax(send);
		    return false;
	    });
	});
}

function searchPano(index){
	window.open("view.html?id="+Table.GetRowData(index).id); 
}

function editPano(index){
	var row = Table.GetRowData(index);
	$('#panoForm')[0].reset();
	$('input[name="name"]').val(row.name);
	$('input[name="subdomain"]').val(row.subdomain);
	$('textarea[name="intro"]').val(row.intro);
	
	layui.use('form', function() {
		var index = layui.layer.open({
			type : 1,
			content : $('#panoForm')
		});
		layer.style(index, {
			width : '500px',
			height : '400px'
		});
		layer.title('编辑项目', index);
		var form = layui.form();
		form.on('submit(submitForm)', function(data){
			var data = $('#panoForm').serializeArray();
			data.push({
				name:'id',
				value:row.id
			});
			var send = {
				url:'/vpoi/update',
				data:data,
				success : function(result) {
					layer.msg(result.message, {
						offset : 't',
						anim : 6
					});
					layer.close(index);
					loadPano();
				}
			};
			sendAjax(send);
		    return false;
	    });
	});
}

function removePano(index) {
	var Message = LayuiHelp.MessageLayui();
	Message.msg = "确定要删除该项目吗？";
	Message.sure = function() {
		var send = {
			url : '/vpoi/remove/' + Table.GetRowData(index).id,
			success : function(result) {
				layer.msg(result.message, {
					offset : 't',
					anim : 6
				});
				loadPano();
			}
		};
		sendAjax(send);
	};
	Message.cancel = function() {

	};
	Message.show();
}
